#include "QDialogTestResult.h"
#include <QPushButton>
#include "globalData.h"
#include "QDialogUnclockNg.h"

QDialogTestResult::QDialogTestResult(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);

	diyUi();
	createAction();
}

QDialogTestResult::~QDialogTestResult()
{
}

void QDialogTestResult::createAction()
{
	QObject::connect(ui.pushButton_unlockNg, SIGNAL(clicked()), this, SLOT(slotButtonClicked()));
	QObject::connect(ui.pushButton_close, SIGNAL(clicked()), this, SLOT(slotButtonClicked()));
}

void QDialogTestResult::setStatus(int ret)
{
	if (OK == ret)
	{
		ui.label_result->setStyleSheet("QLabel{background-color:rgb(255,255,255);border:none;color:green;}");
		ui.label_result->setText("PASS");
		ui.pushButton_unlockNg->hide();
		ui.pushButton_close->show();
	}
	else
	{
		ui.label_result->setStyleSheet("QLabel{background-color:rgb(255,255,255);border:none;color:red;}");
		ui.label_result->setText("NG");
		if (NG_CLOCK == m_ngLockEnable)
		{
			ui.pushButton_unlockNg->show();
			ui.pushButton_close->hide();
		}
		else
		{
			ui.pushButton_unlockNg->hide();
			ui.pushButton_close->show();
		}
	}
}

void QDialogTestResult::slotButtonClicked()
{
	QPushButton* senderObject = qobject_cast<QPushButton*>(sender());
	if (NULL == senderObject)
	{
		return;
	}
	if ("pushButton_close" == senderObject->objectName())
	{
		QDialog::accept();
	}
	else if ("pushButton_unlockNg" == senderObject->objectName())
	{
		QDialogUnclockNg* QDialogUnclockNgTmp = new QDialogUnclockNg(this);
		if (QDialog::Accepted == QDialogUnclockNgTmp->exec())
		{
			ui.pushButton_close->show();
			emit signalChildWidgetMsg(MSG_UNLOCK, QList<QByteArray>());
		}
		delete QDialogUnclockNgTmp;
		QDialogUnclockNgTmp = NULL;
	}
}

void QDialogTestResult::diyUi()
{
	setWindowFlags((windowFlags() & ~Qt::WindowCloseButtonHint));
	setStyleSheet("QDialog{background-color:rgb(255,255,255);border:none;}");

	ui.label_result->setStyleSheet("QLabel{background-color:rgb(255,255,255);border:none;color:green;}");

	ui.pushButton_unlockNg->setStyleSheet(
		"QPushButton{background-color:rgb(2,113,215);border:none;color:white;border-radius:5px;}"
		"QPushButton::hover{background-color:rgb(219,229,239);border:none;color:black;border-radius:5px;}"
		"QPushButton::pressed{background-color:rgb(2,113,215);border:none;color:white;border-radius:5px;}");

	ui.pushButton_close->setStyleSheet(
		"QPushButton{background-color:rgb(228,138,18);border:none;color:white;border-radius:5px;}"
		"QPushButton::hover{background-color:rgb(219,229,239);border:none;color:black;border-radius:5px;}"
		"QPushButton::pressed{background-color:rgb(228,138,18);border:none;color:white;border-radius:5px;}");

	ui.pushButton_unlockNg->hide();
}